package logic

import (
	"context"
	"renting-demo/order_srv/order"

	"renting-demo/api/internal/svc"
	"renting-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PayOrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPayOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PayOrderLogic {
	return &PayOrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PayOrderLogic) PayOrder(req *types.PayOrderReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.OrderServer.Pay(context.Background(), &order.PayOrderReq{
		Orderid: int64(req.Orderid),
	})
	if res.Status == "0" {
		return &types.Data{
			Code:    10001,
			Message: "调用支付接口失败",
		}, nil
	}
	return &types.Data{
		Code:    200,
		Message: "调用支付接口成功",
		Data: map[string]string{
			"url": res.Status,
		},
	}, nil
}
